
$().ready(function() {
    validateRule();
});

$.validator.setDefaults({
    submitHandler : function() {
        save();
    }
});

function save() {
    $.ajax({
        cache : true,
        type : "GET",
        url : "/sys/vipCdk/addVipCdk",
        data : $('#form').serialize(),// 你的formid
        async : false,

        success : function(data) {
            if (data.code == 0) {
                parent.layer.msg("操作成功");
                parent.reLoad();
                var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                parent.layer.close(index);
            } else {
                if (data.msg) {
                    parent.layer.alert(data.msg)
                }else {
                    window.location.href = "/";
                }
            }

        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#form").validate({
        rules : {
            total : {
                required : true
            },
            centreId : {
                required : true
            },
            typeId : {
                required : true
            },
            dueTime : {
                required : true
            }
        },
        messages : {
            total : {
                required : icon + "数量不能为空"
            },
            centreId : {
                required : icon + "商户名不能为空"
            },
            typeId : {
                required : icon + "服务内容不能为空"
            },
            dueTime : {
                required : icon + "服务期限不能为空"
            }
        }
    })
}

